package com.shrct.businessprocess.customerservice.impl;

import com.shrct.businessprocess.customerservice.RCNonProjectService;
import com.shrct.businessprocess.customerservice.RCNonProjectServiceCriteria;
import com.shrct.businessprocess.customerservice.RCNonProjectServiceStatus;
import com.shrct.businessprocess.organization.RCEmployee;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import org.hibernate.Query;

public class RCNonProjectServiceCriteriaImpl extends HQLBasedPagedQueryCriteria<RCNonProjectService> implements RCNonProjectServiceCriteria {
  private String info;
  
  public String getInfo() {
    return this.info;
  }
  
  public RCNonProjectServiceCriteria setInfo(final String info) {
    this.info = info;
    return this;			
    
  }
  
  private RCEmployee worker;
  
  public RCEmployee getWorker() {
    return this.worker;
  }
  
  public RCNonProjectServiceCriteria setWorker(final RCEmployee worker) {
    this.worker = worker;
    return this;			
    
  }
  
  private Boolean includeFinished;
  
  public Boolean getIncludeFinished() {
    return this.includeFinished;
  }
  
  public RCNonProjectServiceCriteria setIncludeFinished(final Boolean includeFinished) {
    this.includeFinished = includeFinished;
    return this;			
    
  }
  
  private RCNonProjectServiceStatus finishedStatus;
  
  public RCNonProjectServiceStatus getFinishedStatus() {
    return this.finishedStatus;
  }
  
  public RCNonProjectServiceCriteria setFinishedStatus(final RCNonProjectServiceStatus finishedStatus) {
    this.finishedStatus = finishedStatus;
    return this;			
    
  }
  
  private RCEmployee sales;
  
  public RCEmployee getSales() {
    return this.sales;
  }
  
  public RCNonProjectServiceCriteria setSales(final RCEmployee sales) {
    this.sales = sales;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from com.shrct.businessprocess.customerservice.impl.RCNonProjectServiceImpl this  left join  this.workers as worker ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) ){
    	hql += " and ((((((this.customerName  LIKE :info) or (this.customerLinkPerson  LIKE :info)) or (this.customerLinkMail  LIKE :info)) or (this.customerLinkPhone  LIKE :info)) or (this.customerLinkAddress  LIKE :info)) or (this.deviceSupplier  LIKE :info))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getWorker()) ){
    	hql += " and ((worker) = (:worker))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIncludeFinished()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getFinishedStatus()) ){
    	hql += " and (((:includeFinished) = (true)) or ((this.status) <> (:finishedStatus)))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSales()) ){
    	hql += " and ((this.sales) = (:sales))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    addOrder("this.applyDate",edu.fudan.mylang.pf.query.OrderItem.DESC);
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo())){
    	query.setParameter("info",getInfo()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getWorker())){
    	query.setParameter("worker",getWorker()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIncludeFinished())){
    	query.setParameter("includeFinished",getIncludeFinished()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getFinishedStatus())){
    	query.setParameter("finishedStatus",getFinishedStatus()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSales())){
    	query.setParameter("sales",getSales()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return true;
  }
  
  public RCNonProjectServiceCriteriaImpl() {
    initOrderBys();
  }
}
